#ifndef CONFIGMANAGER_H
#define CONFIGMANAGER_H

#include <QObject>
#include <QSettings>
#include <QStandardPaths>

class ConfigManager : public QObject
{
    Q_OBJECT
public:
    static ConfigManager& instance();

    // Network
    QString cameraIP() const;
    quint16 cameraPort() const;
    QString mcuIP() const;
    quint16 mcuPort() const;

    quint16 icstcpPort() const;
    quint16 icsCameraUdpPort() const;
    quint16 icsMcuUdpPort() const;
    QString slaveIp(int index) const;
    quint16 slavePort() const;

    // Paths
    QString binPath() const;
    QString fitsPath() const;
    QString logPath() const;

    // Temperature
    double ccdTargetTemp() const;
    double coolerTargetTemp() const;
    double coolerTargetVoltage() const;

    void setValue(const QString &group, const QString &key, const QVariant &value);


    double ccd1MaxTemp() const;
    double ccd2MaxTemp() const;
    double ccd3MaxTemp() const;
    double ccd4MaxTemp() const;
    double base1MaxTemp() const;
    double base2MaxTemp() const;
    double absorbColdMaxTemp() const;
    double circuitMaxTemp() const;
    double dewarMaxTemp() const;
    double backup1MaxTemp() const;
    double backup2MaxTemp() const;
    double outputMax() const;

    double ccd1MinTemp() const;
    double ccd2MinTemp() const;
    double ccd3MinTemp() const;
    double ccd4MinTemp() const;
    double base1MinTemp() const;
    double base2MinTemp() const;
    double absorbColdMinTemp() const;
    double circuitMinTemp() const;
    double dewarMinTemp() const;
    double backup1MinTemp() const;
    double backup2MinTemp() const;
    double outputMin() const;

    double vacuumMax() const;
    double vacuumMin() const;

    double currentMin() const;
    double currentMax() const;

    int alarmDelay() const;

    QString alertServerUrl() const;
    void setAlertServerUrl(const QString &url);

    QString alertServerToken() const;
    void setAlertServerToken(const QString &token);

    int alertServerTimeout() const;
    void setAlertServerTimeout(int timeout);

private:
    QString m_alertServerUrl;
    QString m_alertServerToken;
    int m_alertServerTimeout = 5000; // 默认5秒超时

    explicit ConfigManager(QObject *parent = nullptr);
    QSettings m_settings;
};

#endif // CONFIGMANAGER_H
